What is registry-url?
The registry-url npm package is used to get the set npm registry URL. It is particularly useful when working with npm configurations that may have different registry URLs set for different scopes or projects. This package simplifies the process of retrieving the registry URL that npm will use in the current context.
What are registry-url's main functionalities?
Get the default registry URL
This feature allows you to retrieve the default npm registry URL that is configured on your system.
const registryUrl = require('registry-url');
console.log(registryUrl()); // Outputs the default registry URL
Get the registry URL for a specific scope
This feature allows you to retrieve the npm registry URL for a specific scope, which can be different from the default registry URL.
const registryUrl = require('registry-url');
console.log(registryUrl('@my-scope')); // Outputs the registry URL for the '@my-scope' if configured, otherwise the default.
Other packages similar to registry-url
npm-conf
The npm-conf package is used to get the configuration values that npm would use. It is more general than registry-url as it can retrieve all configuration options, not just the registry URL. However, it is more complex to use if you only need the registry URL.
config-chain
Config-chain is a utility for pulling nested configuration data from INI and JSON files, environment variables, and command-line arguments. It is more versatile than registry-url, offering a broader range of configuration options, but it is also more complex and not specific to npm settings.
registry-url
Get the set npm registry URL
It's usually https://registry.npmjs.org/
, but it's configurable.
Use this if you do anything with the npm registry as users will expect it to use their configured registry.
Install
$ npm install registry-url
Usage
registry = 'https://custom-registry.com/'
const registryUrl = require('registry-url');
console.log(registryUrl());
It can also retrieve the registry URL associated with an npm scope.
@myco:registry = 'https://custom-registry.com/'
const registryUrl = require('registry-url');
console.log(registryUrl('@myco'));
If the provided scope is not in the user's .npmrc
file, then registry-url
will check for the existence of registry
, or if that's not set, fallback to the default npm registry.
License
MIT © Sindre Sorhus